package com.ivr.cm.handler.validate.impl;

import org.apache.log4j.Logger;

import com.ivr.cm.dao.IListBlackDao;
import com.ivr.cm.data.ValidateData;
import com.ivr.cm.handler.validate.ValidateServiceIF;
import com.ivr.cm.service.StateCode;
/**
 * 鉴权用户是否为黑名单
 * @author liugeng
 * @date 2015-12-15
 */
public class ValidateListBlackImpl implements ValidateServiceIF {
	private static Logger logger = Logger.getLogger(ValidateListBlackImpl.class);
	/**定义黑名单数据接口*/
	private IListBlackDao listBlackDao;
	
	@Override
	public int doProcess(ValidateData validateData) {
		/**获得主叫号码*/
		String mobile = validateData.getBaseData().getCalling();
		/**获得业务短号码*/
		String sp_code = validateData.getBaseData().getShort_called();
		logger.info(String.format("[%s][%s][黑名单鉴权]开始", mobile, sp_code));
		
		/**根据主叫号码获得是否存在黑名单里   true 存在  false 不存在*/
		boolean result = listBlackDao.getListBlackList(mobile, sp_code);
		
		if(result){
			logger.info(String.format("[%s][%s][黑名单鉴权]未通过", mobile, sp_code));
			validateData.setResult(ValidateData.RESULT_INVALID_BLOCKUSER);
			validateData.setVoice(ValidateData.VOICE_INVALID_BLOCKUSER);
			validateData.setTimeRemain(0);
			validateData.setStatecode(StateCode.BLACK_USER);
			return ValidateChain.VALIDATE_FINISHED;
		}else{
			logger.info(String.format("[%s][%s][黑名单鉴权]通过", mobile, sp_code));
			return ValidateChain.VALIDATE_CONTINUE;
		}
	}

	public IListBlackDao getListBlackDao() {
		return listBlackDao;
	}
	public void setListBlackDao(IListBlackDao listBlackDao) {
		this.listBlackDao = listBlackDao;
	}
}
